package org.jeecg.modules.demo.cloud_disk.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.demo.cloud_disk.entity.*;
import org.jeecg.modules.demo.cloud_disk.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Description: 评论表
 * @Author: jeecg-boot
 * @Date: 2021-09-15
 * @Version: V1.0
 */
@Api(tags = "首页数据接口")
@RestController
@RequestMapping("/cloud_disk/Index")
@Slf4j
public class IndexDataController extends JeecgController<Comment, ICommentService> {
    @Autowired
    private ICommentService commentService;
    @Autowired
    private IDocumentInfoService iDocumentInfoService;// @Autowired可以提前创建好对象进行操作，就不用管理它的生命周期
    @Autowired
    private IUploadMonthCountService uploadMonthCountService;//统计每月上传次数
    @Autowired
    private IViewUploadNearCountService uploadNearCountService;//近7天上传次数
    @Autowired
    private IViewSumDownloadService sumDownloadService;//总下载次数
    @Autowired
    private IViewRechargeNearService viewRechargeNearService;


    @GetMapping(value = "/get")
    public Result<?> getDate() {
        //去视图里面读取数据，就要调用Mapper,这个架构就是用service数据来调用
        List<DocumentInfo> list = iDocumentInfoService.list();
        return Result.OK(list);
    }


    /**
     * 分页列表查询
     *
     * @param comment
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @AutoLog(value = "评论表-分页列表查询")
    @ApiOperation(value = "评论表-分页列表查询", notes = "评论表-分页列表查询")
    @GetMapping(value = "/list")
    public Result<?> queryPageList(Comment comment,
                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                   HttpServletRequest req) {
        QueryWrapper<Comment> queryWrapper = QueryGenerator.initQueryWrapper(comment, req.getParameterMap());
        Page<Comment> page = new Page<Comment>(pageNo, pageSize);
        IPage<Comment> pageList = commentService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    //删除它只留一个List函数接口
    //改下面地址:
    //@Api(tags="首页数据接口")
    //@RestController
    //@RequestMapping("/cloud_disk/Index")

    //统计每月上传次数
    @GetMapping(value = "/getUploadCount")
    public Result<?> GetUploadCount() {
        List<UploadMonthCount> list = uploadMonthCountService.list();
        return Result.OK(list);
    }

    //统计近7天上传次数
    @GetMapping(value = "/getNearUploadCount")
    public Result<?> GetNearUploadCount() {
        List<ViewUploadNearCount> viewUploadNearCounts = uploadNearCountService.list();
        return Result.OK(viewUploadNearCounts);
    }

    //统计总下载次数
    @GetMapping(value = "/getSumDownload")
    public Result<?> GetSumDownload() {
        List<ViewSumDownload> viewSumDownloads = sumDownloadService.list();
        return Result.OK(viewSumDownloads);
    }

    //统计近7天充值次数
    @GetMapping(value = "/getRechargeNear")
    public Result<?> GetRechargeNear() {
        List<ViewRechargeNear> viewRechargeNear = viewRechargeNearService.list();
        return Result.OK(viewRechargeNear);
    }




}
